"""
SSE模块调研
<并无卵用>
"""
from sse import Sse
from fastapi import FastAPI, Request, Response
import uvicorn

app = FastAPI()


def sse_invoke():
    sse = Sse()
    sse.add_message(event="greet", text="Hello, world!")
    print(str(sse))


@app.get("/events")
async def sse_endpoint(request: Request):
    # 创建 SSE 服务
    sse = Sse(request)

    # 添加事件到 SSE 服务
    sse.add_message("greet", "Hello, world!")

    # 返回 SSE 数据
    return Response(sse)


if __name__ == '__main__':
    # sse_invoke()
    uvicorn.run("demo:app")
    pass